package com.air.ota.vo;

import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Date;

import com.air.ota.util.HexStringUtil;

public class SZTDepositReqTransVO extends SZTBaseReqTransVO {
	
	
	
	
	public SZTDepositReqTransVO(byte[] deviceSequence, byte[] sztSequence,String deviceTriggerTime,
			byte keyIndex,byte[] cardAppSequence,byte[] cardRandom,
			byte[] ewalletTransSequence,byte[] ewalletRemain,byte[] amount,
			byte transTypeTag,byte[] terminalCode,byte[] mac1,
			byte[] depositInfoFile,byte[] lastTransData,byte[] sumDeviceTransFee)
			throws Exception {
		
		super(deviceSequence, sztSequence,deviceTriggerTime);
		
		
		this.transTypeCode = 0x0C;
		this.subTransTypeCode = 0x10;
		//this.cardPhyType = 0x02;
		this.tranAppendCode = 0x01;
		
		//SimpleDateFormat sdf  = new SimpleDateFormat("yyyyMMddHHmmss");
		//Date current = new Date();
		//this.transDate = HexStringUtil.hexStringToBytes(sdf.format(current));
		
		this.keyIndex = 0x01;
		this.cardAppSequence = cardAppSequence;
		this.cardRandom = cardRandom;
		this.ewalletTransSequence = ewalletTransSequence;
		this.ewalletRemain = ewalletRemain;
		this.amount = amount;
		this.transTypeTag = 0x02;
		this.terminalCode = terminalCode;
		this.mac1 = mac1;
		
		this.depositInfoFile = depositInfoFile;
		this.lastTransData = lastTransData;
		this.sumDeviceTransFee = sumDeviceTransFee;
		this.samCardTransSequence = HexStringUtil.hexStringToBytes("00000000");
		this.cardSamId = Arrays.copyOfRange(this.samId, 0, 4);
		this.cardType = 0x02;
		
		this.transData  = makeTransData();
	}
	
	protected byte   keyIndex;
	protected byte[] cardAppSequence;
	protected byte[] cardRandom;
	protected byte[] ewalletTransSequence;
	protected byte[] ewalletRemain;
	protected byte[] amount;
	protected byte   transTypeTag;
	protected byte[] terminalCode;
	protected byte[] mac1;
	//protected byte[] transDate;
	protected byte[] depositInfoFile;
	protected byte[] lastTransData;
	protected byte[] sumDeviceTransFee;
	protected byte[] samCardTransSequence;
	protected byte[] cardSamId;
	protected byte   cardType;
	
	public byte[] makeTransData(){
		StringBuffer hexStringBuf = new StringBuffer();
		
		hexStringBuf.append(HexStringUtil.byteToHexString(keyIndex));
		hexStringBuf.append(HexStringUtil.bytesToHexString(cardAppSequence));
		hexStringBuf.append(HexStringUtil.bytesToHexString(cardRandom));
		hexStringBuf.append(HexStringUtil.bytesToHexString(ewalletTransSequence));
		hexStringBuf.append(HexStringUtil.bytesToHexString(ewalletRemain));
		hexStringBuf.append(HexStringUtil.bytesToHexString(amount));
		hexStringBuf.append(HexStringUtil.byteToHexString(transTypeTag));
		hexStringBuf.append(HexStringUtil.bytesToHexString(terminalCode));
		hexStringBuf.append(HexStringUtil.bytesToHexString(mac1));
		hexStringBuf.append(transDate);
		hexStringBuf.append(HexStringUtil.bytesToHexString(depositInfoFile));
		hexStringBuf.append(HexStringUtil.bytesToHexString(lastTransData));
		hexStringBuf.append(HexStringUtil.bytesToHexString(sumDeviceTransFee));
		hexStringBuf.append(HexStringUtil.bytesToHexString(samCardTransSequence));
		hexStringBuf.append(HexStringUtil.bytesToHexString(cardSamId));
		hexStringBuf.append(HexStringUtil.byteToHexString(cardType));
		
		return HexStringUtil.hexStringToBytes(hexStringBuf.toString());
	}
	
	
}
